<template>
	<view class="tixian">
		<view class="card">
			<view class="">到账银行卡</view>
			<view class="" @click="choosecard">
				<view class="cardname">
					<text v-if="cardinfo == ''">请选择银行卡</text>
					<text v-else>{{ cardinfo }}</text>
				</view>
			</view>
		</view>
		<view class="box">
			<view class="title">提现金额</view>
			<view class="msg">
				<text class="qian">￥</text>
				<input type="text" v-model="inMoney" />
			</view>
		</view>
		<!-- 		<view class="shouxu">提现将收取手续费5%</view> -->
		<button @click="withdraw">提现</button>
		<u-picker :show="show" :closeOnClickOverlay="true" keyName="cardname" :columns="columns" @confirm="confirm" @close="close" @cancel="cancel"></u-picker>
		<view class="mingxi">
			<view class=""><view class="title">提现明细</view></view>
			<view class="mingximain" v-for="(item, index) in mingxi" :key="index">
				<view class="mingxilist">
					<view class="">{{ item.memo }}</view>
					<view class="">{{ item.money }}元</view>
				</view>
				<view class="time">{{ item.addtime }}</view>
			</view>
		</view>
	</view>
</template>

<script>
import { data } from '../../../uni_modules/uview-ui/libs/mixin/mixin';
export default {
	data() {
		return {
			show: false,
			columns: [],
			cardinfo: '',
			id: '',
			inMoney: null,
			mingxi: ''
		};
	},
	onShow() {
		this.cardlist();
		this.getmingxi();
	},
	methods: {
		getmingxi() {
			let self = this;
			// https://chazhichashi.rchz.top/apiadmin/wallet/withdrawal?token=c66f10250c98680bb6ae90347d8d2109
			self.https('/wallet/withdrawal', {}).then(res => {
				self.mingxi = res.data.data.data;
				self.mingxi.map(function(item) {
					item.addtime = self.timeFormatSeconds(item.addtime * 1000);
				});
			});
		},
		timeFormatSeconds(time) {
			var d = time ? new Date(time) : new Date();
			var year = d.getFullYear();
			var month = d.getMonth() + 1;
			var day = d.getDate();
			var hours = d.getHours();
			var min = d.getMinutes();
			var seconds = d.getSeconds();

			if (month < 10) month = '0' + month;
			if (day < 10) day = '0' + day;
			if (hours < 0) hours = '0' + hours;
			if (min < 10) min = '0' + min;
			if (seconds < 10) seconds = '0' + seconds;

			return year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds;
		},
		cardlist() {
			this.https('/order/getMasterBankList', {}).then(res => {
				// console.log(res.data);
				this.columns[0] = res.data.list;
				console.log(this.columns);
			});
		},
		choosecard() {
			console.log('点击');
			this.show = true;
		},
		confirm(e) {
			console.log('confirm', e);
			this.id = e.value[0].id;
			this.cardinfo = e.value[0].cardname;
			this.show = false;
		},
		close() {
			this.show = false;
		},
		cancel() {
			this.show = false;
		},
		// 提现接口
		withdraw() {
			if (this.inMoney > 0 && this.id != '') {
				this.https('/order/masterWithdraw', { money: this.inMoney, bankcard_id: this.id }).then(res => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					setTimeout(e => {
						uni.navigateTo({
							url: '/pages/user/wallet/wallet'
						});
					}, 1500);
				});
			} else {
				uni.showToast({
					title: '提现金额大于0，银行卡不能为空',
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style scoped lang="scss">
.mingxi {
	background-color: #fff;
	.title {
		margin-bottom: 32rpx;
	}
	.mingximain {
		border-bottom: 1rpx solid #f5f5f5;
		padding: 32rpx;
		margin: 12rpx 0;
		box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);
	}
	.mingxilist {
		display: flex;
		justify-content: space-between;
	}
}
.tixian {
	padding: 32rpx;
	border-radius: 12rpx;
}
page {
	background-color: #f5f5f5;
}
.box {
	padding: 32rpx 0;

	.title {
		font-size: 32rpx;
		padding-bottom: 20rpx;
	}

	.qian {
		font-size: 60rpx;
		font-weight: 600;
	}

	.msg {
		display: flex;
		justify-content: start;
		align-items: center;
		padding: 20rpx 0;

		input {
			font-size: 60rpx;
		}

		border-bottom: #ccc 1rpx solid;
	}
}

.card {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 32rpx 0;
	font-size: 30rpx;
}

.cardname {
	display: flex;
	align-items: center;
}

button {
	width: 220rpx;
	height: 60rpx;
	text-align: center;
	line-height: 60rpx;
	color: #fff;
	background-color: #237f52;
}

.shouxu {
	font-size: 30rpx;
	color: #999;
	padding: 0 0 32rpx 0;
}
</style>
